<?php
function template_main()
{

	// Make sure we have all the global variables we need
	global $context, $settings, $options, $txt, $scripturl, $modSettings, $db_prefix;

	$request = mysql_query("
		SELECT
		m.poster_name,m.poster_time,m.body, m.id_topic, m.id_board, m.id_member, m.body, m.subject, m.id_msg,
		t.id_topic, t.id_board, t.id_first_msg, t.id_member_started, t.id_first_msg, t.id_last_msg, t.num_replies, t.num_views
		FROM vn_cmcis_messages AS m, vn_cmcis_topics AS t
		WHERE m.id_board = 5 AND m.id_topic = t.id_topic AND t.id_member_started = m.id_member AND m.id_msg = t.id_first_msg
		ORDER BY m.poster_time DESC Limit 0,20");
	
	$mostv = mysql_query("
		SELECT
		m.poster_name,m.poster_time,m.body, m.id_topic, m.id_board, m.id_member, m.body, m.subject, m.id_msg,
		t.id_topic, t.id_board, t.id_first_msg, t.id_member_started, t.id_first_msg, t.id_last_msg, t.num_replies, t.num_views
		FROM vn_cmcis_messages AS m, vn_cmcis_topics AS t
		WHERE m.id_topic = t.id_topic AND t.id_member_started = m.id_member AND m.id_msg = t.id_first_msg
		ORDER BY t.num_views DESC Limit 0,15");
		
	$most_app = mysql_query("
		SELECT
		m.poster_name,m.poster_time,m.body, m.id_topic, m.id_board, m.id_member, m.body, m.subject, m.id_msg,
		t.id_topic, t.id_board, t.id_first_msg, t.id_member_started, t.id_first_msg, t.id_last_msg, t.num_replies, t.num_views, t.is_sticky
		FROM vn_cmcis_messages AS m, vn_cmcis_topics AS t
		WHERE m.id_board = 22 AND m.id_topic = t.id_topic AND t.id_member_started = m.id_member AND m.id_msg = t.id_first_msg AND t.is_sticky = 1
		ORDER BY t.num_views DESC Limit 0,15");
	// Catbg header
	/* echo '<div style="heigt:100%;"><div> <img src="Themes/joli_20/images/banner/noel.jpg" width=100%/> </div></div>'; */
	
/* 	echo '<div><OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" WIDTH=100% HEIGHT=285">
		 <PARAM NAME=movie VALUE="Themes/joli_20/images/noel.2012.swf">
		<PARAM NAME=quality VALUE=high>
		<PARAM NAME=menu VALUE=false>
		<EMBED src="Themes/joli_20/images/noel.2012.swf" quality=high WIDTH=100% HEIGHT=285 TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" menu=\"false\"></EMBED>
	 </OBJECT></div>'; */

	// Top tin t?c
	
	function stripBBCode($posterbody) { 
		$pattern = '~\[([^\]]+?)(=[^\]]+?)?\](.+?)\[/\1\]~'; 
		$replace = ''; 
		return preg_replace($pattern, $replace, $posterbody); 
		} 
		
	echo '<br>
	<table border=0 width=100% cellpadding=0 cellspacing=0 style="border-collapse:collapse;">
		<tr>
			<td width=75%>
			<div style="background:url(Themes/joli_20/images/hlogo.png) repeat;padding-left:5px;padding-right:5px;font-size:20px;color:white;height:30px;padding-top:10px;">TIN TỨC BẢO MẬT - VIRUS </div><br>
			';
			while ($row = mysql_fetch_array($request))
			{
			$pt = $row['subject'];
			$postername = $row['poster_name'];
			$postertime = $row['poster_time'];
			$posterbody = $row['body'];
			$nv = $row['num_views'];
			$np = $row['num_replies'];
			$unixtime_to_date = date('jS F Y h:i:s A (T)', $postertime);
			$s = stripBBCode($posterbody);
			$pattern = '/\[img\]([^\[]*)\[/';
			preg_match($pattern, $posterbody, $matches);
			if (preg_match($pattern, $posterbody, $matches) == 0) { $matches[1] = '';}
			echo'
			<div style="padding-bottom:15px;padding-left:10px;padding-right:20px;background-color:white;
			font: 13px/170% lucida grande, lucida Sans Unicode, tahoma, sans-serif;">
			<table width=100% cellpadding=0 cellspacing=0 style="border-collapse:collapse;border-bottom:1px solid #DFDFDF;">
			<tr>
			<td width=30% valign=top><div style="border:1px solid black;padding:1px;"><img src="'.$matches[1].'" width=210></div></td>
			<td width=80% style="padding-left:10px;" valign=top>
			<b><a href="index.php?topic='.$row['id_topic'].'.msg'.$row['id_last_msg'].'?'.$rdo.'#new" style="font-size:16px;">'.strip_tags($pt).'</b></a>
			<br><font color=#002B55><b>'.$postername.'</b></font> | <font color=#BCBCBC>'.$unixtime_to_date.'</font> 
			| <font style="background-color:#002E5B;padding-left:5px;padding-right:5px;font-size:11px;color:white;width:50px;">'.$nv.'V</font>
			| <font style="background-color:#002E5B;padding-left:5px;padding-right:5px;font-size:11px;color:white;width:50px;">'.$np.'RP</font>
			<br>'.substr(str_replace( '<br />', ' ', $s),0,600).'..<br><br>
			</td></tr></table>
			</div>';
			}
			
	echo'	</td>
			<td width=25% valign=top><img src="Themes/joli_20/images/banner/addong.gif">';
			/* <div style="margin-top:5px;color:#002E5B;padding-left:5px;padding-right:5px;font-size:14px; border:5px solid #002E5B;">
			<font style="background-color:#002E5B;padding-left:5px;padding-right:5px;color:white;width:50px;">TOP VIEWS</font>
			'; */
			/* $c = 0;
			while ($row = mysql_fetch_array($mostv))
			{
			$c++;
			$ps = $row['subject'];
			$pn = $row['poster_name'];
			$pt = $row['poster_time'];
			$nv = $row['num_views'];
			$np = $row['num_replies'];
			$unixtime_to_date1 = date('jS F Y', $pt);
			echo '<table width=100% cellpadding=0 cellspacing=0 style="border-collapse:collapse;border-bottom:1px solid #DFDFDF;">
			<tr>
			<td width=80% style="padding-left:10px; font-size:12px;" valign=top>
			<font style="background-color:#002E5B;padding-left:5px;padding-right:5px;font-size:11px;color:white;width:50px;">'.$c.'</font> 
			<b><a href="index.php?topic='.$row['id_topic'].'.msg'.$row['id_last_msg'].'?'.$rdo.'#new" class=aaa>'.strip_tags($ps).'</b></a>
			<br><font color=#002B55><b>'.$pn.'</b></font> | <font color=#BCBCBC>'.$unixtime_to_date1.'</font> 
			</td></tr></table>';
			} */
			
			//Popular App - ung dung sticky
			echo '	
			<div style="margin-top:5px;color:#002E5B;padding-left:5px;padding-right:5px;font-size:14px; border:5px solid #D8B0FF;">
			<font style="padding-left:5px;padding-right:5px;color:white;width:50px;"><b><a href="?board=22.0">POPULAR APP</a></b></font>
			<table width=100% cellpadding=0 cellspacing=0 style="border-collapse:collapse;border-bottom:1px solid #DFDFDF;">
			<tr>
				<td width=80% style="padding-left:10px; font-size:12px;" valign=top align=center>';
				while ($row = mysql_fetch_array($most_app))
					{
					$mas = $row['subject'];
					$mapn = $row['poster_name'];
					$mapt = $row['poster_time'];
					$posterbody = $row['body'];
					$manv = $row['num_views'];
					$manp = $row['num_replies'];
					$unixtime_to_date2 = date('jS F Y', $mapt);
					$s = stripBBCode($posterbody);
					$pattern = '/\[img\]([^\[]*)\[/';
					preg_match($pattern, $posterbody, $matches);
					if (preg_match($pattern, $posterbody, $matches) == 0) { $matches[1] = '';}
					echo '<table width=100% cellpadding=0 cellspacing=0 style="border-collapse:collapse;border-bottom:1px solid #DFDFDF;padding-top:5px;padding-bottom:5px;">
						<tr>
						<td><img src="'.$matches[1].'" width=50></td>
						<td width=80% style="padding-left:10px; font-size:12px;" valign=top>
						<b><a href="index.php?topic='.$row['id_topic'].'.msg'.$row['id_last_msg'].'?'.$rdo.'#new" class=a4>'.strip_tags($mas).'</b></a>
						<br><font color=#002B55>'.$mapn.'</font> | <font color=#BCBCBC>'.$unixtime_to_date2.'</font>
						</td></tr></table>';
					}
			echo '
			</td>
			</tr></table>
			</div>
			<div style="margin-top:5px;color:#002E5B;padding:5px;font-size:14px; border-top:4px solid black; border-bottom:4px solid black;" align=center>
			<font style="padding-left:5px;padding-right:5px;width:50px;"><b>CMC Antivirus Compatible with</b></font><br><br>
			<img src="Themes/joli_20/images/banner/win8.png" width=200/> <br>
			<img src="Themes/joli_20/images/banner/wins8.png" width=200 style="border:1px solid #D2D2D2;"/> <br>
			<img src="Themes/joli_20/images/banner/win7.png"  width=200/> <br>
			<img src="Themes/joli_20/images/banner/winp.jpg" width=200/>  <br>
			</div>
			<div style="margin-top:5px;color:#002E5B;padding:5px;font-size:14px; border:4px solid black;" align=center>
			<b>Certified Product Vendors of</b><br>
			<img src="Themes/joli_20/images/banner/icsa.vd.jpg"  width=140/> <br>
			</td>
		</tr>
	</table>
	';
}

?>
